using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Departments Data Object Class
  /// </summary>
  public partial class DODepartments
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Departments DivisionName
		/// </summary>
		public const string RowDivisionName = "DivisionName";

		/// <summary>
		/// The Table Column for the Departments DepartmentName
		/// </summary>
		public const string RowDepartmentName = "DepartmentName";

		/// <summary>
		/// The Table Column for the Departments PrimaryAuthUserId
		/// </summary>
		public const string RowPrimaryAuthUserId = "PrimaryAuthUser_ID";

		/// <summary>
		/// The Table Column for the Departments SecondaryAuthUserId
		/// </summary>
		public const string RowSecondaryAuthUserId = "SecondaryAuthUser_ID";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spDepartments_Create";
private const string m_StoredProcedureConstDelete = "spDepartments_Delete";
private const string m_StoredProcedureConstRetrieve = "spDepartments_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spDepartments_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spDepartments_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_DivisionName;
		private string m_DepartmentName;
		private long m_PrimaryAuthUserId;
		private long m_SecondaryAuthUserId;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DODepartments> m_Departmentss = new List<DODepartments>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DODepartments() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// DivisionName
		/// </summary>
		/// <remarks>
		/// This property contains the Departments DivisionName
		/// </remarks>
		public string DivisionName
		{
			get { return (this.m_DivisionName); }
			set { this.m_DivisionName = value; }
		}

		/// <summary>
		/// DepartmentName
		/// </summary>
		/// <remarks>
		/// This property contains the Departments DepartmentName
		/// </remarks>
		public string DepartmentName
		{
			get { return (this.m_DepartmentName); }
			set { this.m_DepartmentName = value; }
		}

		/// <summary>
		/// PrimaryAuthUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Departments PrimaryAuthUserId
		/// </remarks>
		public long PrimaryAuthUserId
		{
			get { return (this.m_PrimaryAuthUserId); }
			set { this.m_PrimaryAuthUserId = value; }
		}

		/// <summary>
		/// SecondaryAuthUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Departments SecondaryAuthUserId
		/// </remarks>
		public long SecondaryAuthUserId
		{
			get { return (this.m_SecondaryAuthUserId); }
			set { this.m_SecondaryAuthUserId = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DODepartments> Departmentss
	{
	  get { return m_Departmentss; }
	  set { m_Departmentss = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowDepartmentName + "=" + this.DepartmentName);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowDivisionName].ToString() != "")
			this.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			this.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowPrimaryAuthUserId].ToString() != "")
			this.PrimaryAuthUserId = long.Parse(dr[RowPrimaryAuthUserId].ToString());

		if (dr[RowSecondaryAuthUserId].ToString() != "")
			this.SecondaryAuthUserId = long.Parse(dr[RowSecondaryAuthUserId].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DODepartments Departments = new DODepartments();
			
					if (dr[RowDivisionName].ToString() != "")
			Departments.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			Departments.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowPrimaryAuthUserId].ToString() != "")
			Departments.PrimaryAuthUserId = long.Parse(dr[RowPrimaryAuthUserId].ToString());

		if (dr[RowSecondaryAuthUserId].ToString() != "")
			Departments.SecondaryAuthUserId = long.Parse(dr[RowSecondaryAuthUserId].ToString());

            this.Departmentss.Add(Departments);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
